package 恰好型滑动窗口

func numberOfSubarrays(nums []int, k int) int {
	s1 := 0
	s2 := 0
	left1, left2 := 0, 0
	cnt1, cnt2 := 0, 0
	for right, num := range nums {
		if num%2 == 1 {
			s1++
			s2++
		}
		for s1 >= k {
			if nums[left1]%2 == 1 && left1 <= right {
				s1--
			}
			left1++
		}
		cnt1 += left1
		for s2 >= k+1 {
			if nums[left2]%2 == 1 && left2 <= right {
				s2--
			}
			left2++
		}
		cnt2 += left2
	}
	return cnt1 - cnt2
}
